﻿using System;

namespace PJ.Data.WCF
{
    public abstract class ItemWCFProvider<TItemData> : EntityWCFProvider<TItemData>, IItemWCFProvider<TItemData>
        where TItemData : BaseItemData, IItemData, new()
    {
        #region Constructor

        public ItemWCFProvider(IItemProvider provider)
            : base(provider)
        {
        }

        #endregion

        #region Interface implementation

        /// <summary>
        /// Global search of an item based on it's name (and other text fields depending on object type. Like address for partner object).
        /// </summary>
        /// <param name="searchText">Search criteria</param>
        /// <returns>The list of found objects global id or null</returns>
        /// <exception cref="ArgumentNullException"><paramref name="searchText"/> can't be <see langref="null"/> or empty</exception>              
        public string[] Search(string sessionId, string searchText, int mode)
        {
            return Provider.Search(searchText, (GetDataMode)mode);
        }


        /// <summary>
        /// Gets the <see cref="IItemData">Item data</see> from the data source
        /// </summary>
        /// <param name="name">Entity Name</param>
        /// <returns>The <see cref="IItemData">Item data</see> instance</returns>
        /// <exception cref="ArgumentNullException"><paramref name="name"/> can't be <see langref="null"/> or empty</exception>
        /// <exception cref="DataNotFoundException">If no <see cref="IItemData">Item data</see> exists having Name property equal to <paramref name="name"/></exception>
        public TItemData GetByName(string sessionId, string name, int mode)
        {
            return (TItemData)Provider.GetByName(name, (GetDataMode)mode);
        }


        /// <summary>
        /// Gets the <see cref="IItemData">Item data</see> from the data source
        /// </summary>
        /// <param name="aliasName">Entity Alias</param>
        /// <returns>The <see cref="IItemData">Item data</see> instance</returns>
        /// <exception cref="ArgumentNullException"><paramref name="aliasName"/> can't be <see langref="null"/> or empty</exception>
        /// <exception cref="DataNotFoundException">If no <see cref="IItemData">Item data</see> exists having Alias property equal to <paramref name="aliasName"/></exception>
        public TItemData GetByAlias(string sessionId, string aliasName, int mode)
        {
            return (TItemData)Provider.GetByAlias(aliasName, (GetDataMode)mode);
        }


        #endregion

        #region Interface override


        #endregion

        #region Protected

        new protected IItemProvider Provider
        {
            get
            {
                return (IItemProvider)base.Provider;
            }
        }

        #endregion


    }
}
